<template>
  <div v-loading="loading">
    <div class="header-search cad-box">
      <el-input
        v-model="searchValue.realName"
        style="width: 20%"
        clearable
        placeholder="请输入评估计划名称"
      />
      <el-button
        type="primary"
        style="margin: 0px 10px"
        @click="handleProblemRectificationList"
      >搜索</el-button>
    </div>

    <div class="content-table cad-box">
      <el-table :data="tableData" style="width: 100%">
        <el-table-column label="序号" type="index" align="center" />
        <el-table-column prop="name" label="评估计划名称" align="center" />
        <el-table-column prop="status" label="整改状态" align="center">
          <template slot-scope="scope">
            {{
              options2.find((item) => item.value === scope.row.problemStatus)
                .label
            }}
          </template>
        </el-table-column>
        <el-table-column prop="result" label="整改结果" align="center">
          <template slot-scope="scope">
            {{
              scope.row.result
                ? options3.find((item) => item.value === scope.row.result).label
                : "-"
            }}
          </template>
        </el-table-column>
        <el-table-column prop="createTime" label="创建时间" align="center" />
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button
              type="text"
              size="small"
              @click="handleInfo(scope.row, 1)"
            >编辑</el-button>
            <el-button
              type="text"
              size="small"
              @click="handleInfo(scope.row, 2)"
            >详情</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div style="text-align: right">
        <el-pagination
          :current-page="pagination.pageNum"
          :page-sizes="[10, 15, 30, 50]"
          :page-size="pagination.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>

    <el-drawer title="详情" :visible.sync="drawer" :direction="direction">
      <div class="drawer_box">
        <div class="drawer_item">标题：{{ infoItem.name }}</div>
        <div class="drawer_item" style="justify-content: space-between">
          <div>类型：{{ infoItem.name }}</div>
          <div style="margin-left: 50px">分类：{{ infoItem.name }}</div>
        </div>
        <div class="drawer_item">备注：{{ infoItem.name }}</div>
        <div class="drawer_item">文件：{{ infoItem.name }}</div>
      </div>
    </el-drawer>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { problemRectificationList } from './api'
export default {
  data () {
    return {
      options1: [
        {
          value: 0,
          label: '长沙卫健委'
        },
        {
          value: 1,
          label: '国家卫健委'
        }
      ],
      options3: [
        {
          value: 1,
          label: '已通过'
        },
        {
          value: 2,
          label: '已拒绝'
        }
      ],
      options2: [
        {
          value: 0,
          label: '未整改'
        },
        {
          value: 1,
          label: '整改中'
        },
        {
          value: 2,
          label: '已整改'
        }
      ],
      value1: '',
      value2: '',
      drawer: false,
      direction: 'rtl',
      infoItem: {},
      loading: false,
      searchValue: {
        realName: '',
        status: ''
      },
      tableData: [],
      pagination: {
        pageNum: 0,
        pageSize: 10
      },
      total: 0
    }
  },
  computed: {
    ...mapGetters(['curArea', 'user'])
  },
  created () {
    this.handleProblemRectificationList()
  },
  mounted () {},
  methods: {
    async handleProblemRectificationList () {
      const res = await problemRectificationList({
        pageNum: this.pagination.pageNum,
        pageSize: this.pagination.pageSize,
        areaId: this.curArea.id,
        name: this.searchValue.realName
      })
      this.tableData = res.records
      this.total = Number(res.total)
      console.log(res, 'handleProblemRectificationList')
    },
    handleInfo (item, type) {
      type === 1
        ? this.$router.push(
          `/government/rectificationEdit?id=${item.id}&status=${item.problemStatus}`
        )
        : this.$router.push(
          `/government/rectificationDetail?id=${item.id}&status=${item.problemStatus}`
        )
    },
    onSubmit () {},
    getTableList () {},
    handleSizeChange (val) {
      console.log(`每页 ${val} 条`)
      this.pagination.pageSize = val
      this.getTableList()
    },

    handleCurrentChange (val) {
      console.log(`当前页: ${val}`)
      this.pagination.pageNum = val
      this.getTableList()
    }
  }
}
</script>

<style scoped lang="scss">
::v-deep .el-drawer__header {
  color: #000 !important;
  font-size: 18px !important;
}

.header-search {
  display: flex;
  margin-bottom: 30px;

  .select-box {
    width: 20%;
    margin: 0 20px;
  }
}

.drawer_box {
  width: 100%;
  padding: 0px 50px;
  .drawer_item {
    display: flex;
    justify-content: flex-start;
    margin-bottom: 20px;
    padding: 10px;
  }
}
</style>
